package com.yang.ossservice.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author yds
 * @program edu
 * @description 作为读取配置文件的工具类
 * @create 2020-11-26 14:48
 **/
//当项目启动后，执行InitializingBean接口的afterPropertiesSet
@Component
public class ConstandPropertiesUtils implements InitializingBean {

    @Value("${aliyun.oss.file.endpoint}")
    private String endPoint;

    @Value("${aliyun.oss.file.keyid}")
    private String keyId;

    @Value("${aliyun.oss.file.keysecret}")
    private String keySecret;

    @Value("${aliyun.oss.file.bucketname}")
    private String bucketName;

    //定义公开静态常量
    public static String END_POINT;

    public static String KEY_ID;

    public static String KEY_SECRET;

    public static String BUCKET_NAME;


    /***
     * 当类实现了InitializingBean,读取配置文件常量后，执行此方法
     * 将私有化常量复制到自定义的公开静态常量中
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        END_POINT=endPoint;
        KEY_ID=keyId;
        KEY_SECRET=keySecret;
        BUCKET_NAME=bucketName;

    }
}
